https://leetcode.cn/problems/word-ladder/
class Solution {
public:
    int ladderLength(string beginWord, string endWord, vector<string>& wordList) {
        unordered_set<string> hash(wordList.begin(),wordList.end());
        unordered_set<string> visit;

        if(!hash.count(endWord))  return 0;
        if(beginWord==endWord) return 0;
        queue<string> q;
        q.push(beginWord);
        visit.insert(beginWord);
       
       int len=1;
        while(!q.empty())
        {
            len++;
            int sz=q.size();
            while(sz--)
            {
                string  t=q.front();
                q.pop();
                for(int i=0;i<t.size();i++)
                {
                    string tmp=t;
                    for(char j='a';j<='z';j++)
                    {
                        tmp[i]=j;
                        //判断不在vist和存在单词
                        if(tmp==endWord)
                            return len;
                        if(!visit.count(tmp)&&hash.count(tmp))
                        {
                            q.push(tmp);
                            visit.insert(tmp);
                        }
                    }
                }
            }
        }
        return 0;
    }
};